package com.fare.util;

import java.util.List;
import java.util.Map;
import java.util.ArrayList;

public class FusionChartsUtil {
	
	public static String getXML(Map<String,List<Integer>> channelPriceMap,List<String> dates){
		String	XML = "<?xml version='1.0'?>" +
		"<chart caption='各网站价格图' subCaption='For the year 2012' numberPrefix='￥' " +
		"sformatNumberScale='0' formatNumberScale='0' sNumberPrefix='￥' rotateNames='1' syncAxisLimits='1' rotateValues='0' showSum='0'><categories>";
		for(String s:dates){
			XML += "<category label='"+s+"'/>";
		}
		XML += "</categories>";
		for(String channelName:channelPriceMap.keySet()){
			XML += "<dataset seriesName='"+channelName+"'>";
			for(Integer i:channelPriceMap.get(channelName)){
//				if (i == 0||i == null) {
//					continue;
//				}
				XML += "<set value='"+i+"'/>";
			}
			XML += "</dataset>";
		}
			XML += "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"+
			"	<set value='1400'/>"+
			"<set value='1100'/>"+
			"<set value='1480'/>"+
			"<set value='1300'/>"+
			"<set value='1480'/>"+
		"</lineset>"+
	"</chart>";
		return XML;
	}
	
	public static String getXML(List<List<Integer>> pricesList,List<String> dates){
		List<String> newDates = new ArrayList<String>();
		for (int i=0;i<pricesList.get(0).size();i++) {
			newDates.add(dates.get(i));
		}
		String	XML = "<?xml version='1.0'?>" +
		"<chart caption='价格走势' subCaption='For the year 2012' numberPrefix='￥' " +
		"sformatNumberScale='0' formatNumberScale='0' sNumberPrefix='￥' rotateNames='1' syncAxisLimits='1' rotateValues='0' showSum='0'><categories>";
		for(String s:newDates){
			XML += "<category label='"+s+"'/>";
		}
		XML += "</categories>";
		int i = 0;
		for (List<Integer> prices : pricesList) {
			if (i == 0) XML += "<dataset seriesName='去程'>";
			else XML += "<dataset seriesName='回程'>";
			for(Integer price:prices){
				XML += "<set value='"+price+"'/>";
			}
			XML += "</dataset>";
			i++;
		}
		XML += "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"+
		"<set value='1400'/>"+
		"<set value='1100'/>"+
		"<set value='1480'/>"+
		"<set value='1300'/>"+
		"<set value='1480'/>"+
		"</lineset>"+
		"</chart>";
		return XML;
	}

}
